from django.db import models
from django.contrib.auth.models import AbstractUser
from django.utils import timezone


# Create your models here.

class Clazz(models.Model):
    name = models.CharField(max_length=50, db_comment="班级名", null=True, blank=True)
    manage_name = models.CharField(max_length=20, db_comment="班主任", null=True, blank=True)
    start_time = models.DateTimeField(db_comment="开班时间", null=True, blank=True)
    duration = models.IntegerField(db_comment="课程时常", null=True, blank=True)
    creator = models.CharField(max_length=50, db_comment="创建者", null=True, blank=True)
    state = models.BooleanField(db_comment="班级状态", null=True, blank=True)

    create_time = models.DateTimeField(db_comment="添加时间", null=True, blank=True, default=timezone.now)

    update_time = models.DateTimeField(db_comment="修改时间", null=True, blank=True)

    delete_time = models.DateTimeField(db_comment="删除时间", null=True, blank=True)

    is_delete = models.BooleanField(db_comment="是否删除", null=True, blank=True, default=False)

    class Meta:
        db_table = "tb_clazz"


class Role(models.Model):
    name = models.CharField(max_length=50, db_comment="角色名", null=True, blank=True)
    code = models.CharField(max_length=50, db_comment="角色编码", null=True, blank=True)
    descript = models.TextField(db_comment="角色描述", null=True, blank=True)
    state = models.BooleanField(db_comment="班级状态", null=True, blank=True)

    create_time = models.DateTimeField(db_comment="添加时间", null=True, blank=True, default=timezone.now)

    update_time = models.DateTimeField(db_comment="修改时间", null=True, blank=True)

    delete_time = models.DateTimeField(db_comment="删除时间", null=True, blank=True)

    is_delete = models.BooleanField(db_comment="是否删除", null=True, blank=True, default=False)

    class Meta:
        db_table = "tb_role"


class User(AbstractUser):
    tel = models.CharField(max_length=11, db_comment='手机号', null=True, blank=True)
    name = models.CharField(max_length=20, db_comment='真实姓名', null=True, blank=True)
    delete_time = models.DateTimeField(db_comment="删除时间", null=True, blank=True)

    is_delete = models.BooleanField(db_comment="是否删除", null=True, blank=True, default=False)

    role = models.ForeignKey(to=Role, on_delete=models.DO_NOTHING, blank=True, null=True, related_name='users')

    clazz = models.ForeignKey(to=Clazz, on_delete=models.DO_NOTHING, blank=True, null=True, related_name='users')

    class Meta:
        db_table = "auth_user"
        swappable = 'AUTH_USER_MODEL'

# class Address(models.Model):
#     pro = models.CharField(max_length=20, db_comment='省份')
#     city = models.CharField(max_length=20, db_comment='城市')
#     country = models.CharField(max_length=20, db_comment='区县')
#     detail = models.TextField(db_comment='详细地址')
#     user = models.ForeignKey(to=User, on_delete=models.DO_NOTHING, blank=True, null=True, related_name="address_list")
#
#     class Meta:
#         db_table = "tb_address"
